package com.yunnuo.system.role.dao;

import com.yunnuo.system.role.entity.Role;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by w_weihf on 2018/7/23.
 */
@Repository
@Transactional
public interface IRoleDao  extends JpaRepository<Role,String>,JpaSpecificationExecutor<Role> {

    @Query(value = "select  r from  Role r left join  UserRole ro on r.id =ro.roleId where ro.userId =?1 ")
    List<Role> selectAllRoleByUserId(String userId);


    /**
     * 根据角色名称查询角色
     * @param roleName
     * @return
     */
    Role findAllByRoleName(String roleName);

    int countAllByIdAndRoleName(String id, String roleName);

    String countAllByRoleName(String roleName);
}
